package com.sevenre.trackre.driver;

import com.sevenre.trackre.driver.utils.NetworkConnectivity;
import com.sevenre.trackre.driver.utils.Utils;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;

public class ActivityHome extends Activity implements OnClickListener {

	View pick, drop, setting, simply_track, other_info;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_home);
		setUpUI();
	}

	private void setUpUI() {
		pick = findViewById(R.id.home_pick_up);
		drop = findViewById(R.id.home_drop);
		setting = findViewById(R.id.home_setting);
		simply_track = findViewById(R.id.home_just_track);
		simply_track.setEnabled(false);
		other_info = findViewById(R.id.home_other_info);
		other_info.setEnabled(false);

		pick.setOnClickListener(ActivityHome.this);
		drop.setOnClickListener(ActivityHome.this);
		setting.setOnClickListener(ActivityHome.this);
		other_info.setOnClickListener(ActivityHome.this);
		simply_track.setOnClickListener(ActivityHome.this);

	}

	@Override
	public void onClick(View v) {
		Intent i = new Intent();
		switch (v.getId()) {
		case R.id.home_drop:
			i.setClass(ActivityHome.this, ActivityDropList.class);
			startActivity(i);
			break;
		case R.id.home_pick_up:
			i.setClass(ActivityHome.this, ActivityPickUpList.class);
			startActivity(i);
			break;
		case R.id.home_setting:
			i.setClass(ActivityHome.this, ActivitySetting.class);
			//startActivity(i);
			break;
		case R.id.home_just_track:
			i.setClass(ActivityHome.this, ActivitySimplyTrack.class);
			//startActivity(i);
			break;
		}
	}
	
	@Override
	protected void onResume() {
		super.onResume();
		if (!NetworkConnectivity.isConnectedToInternet(getApplicationContext())){
			AlertDialog.Builder builder = new AlertDialog.Builder(ActivityHome.this);
			builder.setTitle("Network connectivity not found");
			builder.setMessage("Please start your Data Plan");
			builder.setPositiveButton("Yes", new android.content.DialogInterface.OnClickListener() {
				@Override
				public void onClick(DialogInterface dialog, int which) {
					startActivity(Utils.intentForNetworkAccess());
				}
			});
			builder.setNegativeButton("No", new android.content.DialogInterface.OnClickListener() {
				@Override
				public void onClick(DialogInterface dialog, int which) {
					dialog.dismiss();
				}
			});
			builder.create().show();
		}
	}
}
